package com.ss.android.article.base.feature.feed.vh;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.article.base.feature.c.FeedItemBehavior;
import com.ss.android.article.base.feature.feed.activity.InfoLayout;
import com.ss.android.article.base.feature.model.AdsData;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.NetworkStatusMonitor;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.newmedia.a.TimeFormatter;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONObject;

import java.util.concurrent.atomic.AtomicBoolean;

public final class LbsAdViewHolder extends af {
    private AdsData mAdsData;

    public LbsAdViewHolder(Context arg1,
                           NetworkStatusMonitor arg2,
                           FeedItemBehavior arg3,
                           ArticleActionHelper arg4,
                           int arg5,
                           TimeFormatter arg6,
                           int actualItemImageWidth,
                           int actualItemImageHeight,
                           int arg9,
                           int arg10,
                           int arg11,
                           AtomicBoolean arg12) {
        super(arg1, arg2, arg3, arg4, arg5, arg6, actualItemImageWidth, actualItemImageHeight, arg9, arg10, arg11, arg12);
    }

    protected final void a(View arg10) {
        if (this.context != null && this.mAdsData != null && !android.support.design.a.isTextEmpty(this.mAdsData._openUrl)) {
            AppUtil.b(this.context, this.mAdsData._openUrl);
            try {
                JSONObject v8 = new JSONObject();
                if (!android.support.design.a.isTextEmpty(this.mAdsData.logExtra)) {
                    v8.put("log_extra", this.mAdsData.logExtra);
                }
                MobClickCombiner.onEvent(this.context, "embeded_ad", "click", this.mAdsData.id, 1, v8);
            } catch (Exception e) {
            }
        }
    }

    protected final void a_(InfoLayout.Info info) {
        if (this.mAdsData != null) {
            String v0 = android.support.design.a.isTextEmpty(this.mAdsData.source) ? this.mAdsData.appName : this.mAdsData.source;
            if (android.support.design.a.isTextEmpty(v0)) {
                return;
            }
            info.a |= 1;
            info.d = v0;
        }
    }

    protected final void b(ImageInfo imageInfo) {
        if (this.mAdsData != null && this.mRightImageAdImageTagIcon != null && imageInfo != null) {
            super.b(imageInfo);
            if (android.support.design.a.isTextEmpty(this.mAdsData.appointment)) {
                UIUtils.setVisibility(this.mRightImageAdImageTagIcon, View.GONE);
            } else {
                UIUtils.setVisibility(this.mRightImageAdImageTagIcon, View.VISIBLE);
                this.mRightImageAdImageTagIcon.setText(this.mAdsData.appointment);
            }
        }
    }

    protected final void g() {
        int v4 = 8;
        if (this.mCellRef != null) {
            this.mAdsData = this.mCellRef.embeddedAd;
            if (this.mAdsData != null) {
                super.g();
                this.initRightImageAdLayout();
                this.f(this.mAdsData.m);
                this.c(this.mAdsData.m);
                UIUtils.setVisibility(((af) this).mLargeImageAdInfoLayout, v4);
                UIUtils.setVisibility(((af) this).mLargeImageLayout, v4);
                UIUtils.setVisibility(((af) this).mRightImageAdLayout, 0);
                UIUtils.setVisibility(((af) this).mRightImageAdLayout_AdInfoLayout, 0);
                UIUtils.setVisibility(((af) this).mLargeImageAdInfoLayout_AdInfoLayout, 0);
                this.a(this.mAdsData.image);
                this.a(this.mAdsData.description, this.mAdsData.m);
                this.mImage3InfoLayout.setVisibility(View.VISIBLE);
                InfoLayout.Info v0 = InfoLayout.Info.acquireInfo();
                this.b(v0);
                this.mImage3InfoLayout.setDislikeOnClickListener(this.popIconClickListener);
                this.mImage3InfoLayout.setMoreActionClickListener(this.moreActionClickListener);
                this.mImage3InfoLayout.a(v0);
                String v0_1 = this.mAdsData == null || !this.mAdsData.isValid() ? null : this.mAdsData.merchantArea + " / " + this.mAdsData.shop + " " + this.mAdsData.distance;
                if (!android.support.design.a.isTextEmpty(v0_1) && this.mLbsAdAddressInfoTv != null) {
                    this.mLbsAdAddressInfoTv.setText(((CharSequence) v0_1));
                }

                if (this.mAdsData != null) {
                    if (this.mLbsAdInfoLayout != null) {
                        this.mLbsAdInfoLayout.setVisibility(View.VISIBLE);
                    }

                    if (this.mLbsAdCurrentPriceTv != null) {
                        this.mLbsAdCurrentPriceTv.setText(this.mAdsData.price);
                    }

                    if (this.mLbsAdOriginPriceTv != null) {
                        this.mLbsAdOriginPriceTv.setText(this.mAdsData.value);
                        this.mLbsAdOriginPriceTv.getPaint().setFlags(16);
                    }

                    if (this.mLbsAdSoldNumberTv == null) {
                    } else if (android.support.design.a.isTextEmpty(this.mAdsData.sales)) {
                    } else {
                        this.mLbsAdSoldNumberTv.setText(this.mAdsData.sales);
                    }
                }

                label_92:
                this.l();
                UIUtils.setVisibility(this.mLbsAdInfoLayout, 0);
                UIUtils.setVisibility(this.mActionAdInfoLayout, v4);
                UIUtils.setVisibility(this.mAppAdInfoLayout, v4);
                UIUtils.setVisibility(this.mAdActionBtnLayout, v4);
            }
        }
    }

    protected final void j() {
        if (this.mRightImageAdImageLayout != null && this.mAdsData != null && this.mAdsData.image != null && (this.mAdsData.image.isValid())) {
            ViewGroup.LayoutParams v0 = this.mRightImageAdImageLayout.getLayoutParams();
            if (android.support.design.a.o(this.context)) {
                v0.width = com.ss.android.article.base.feature.app.a.b.f;
                v0.height = com.ss.android.article.base.feature.app.a.b.f * this.mAdsData.image.mHeight / this.mAdsData.image.mWidth;
            } else {
                v0.width = this.mImageViewWidth;
                v0.height = this.mImageViewWidth * this.mAdsData.image.mHeight / this.mAdsData.image.mWidth;
            }
        }
    }

    protected final void l_() {
        if (this.mLargeImage != null && this.mAdsData != null && this.mAdsData.image != null && (this.mAdsData.image.isValid())) {
            b(this.mLargeImage, this.r * this.mAdsData.image.mHeight / this.mAdsData.image.mWidth);
        }
    }

    protected final int m() {
        int v0 = this.mAdsData != null ? this.mAdsData.m : 0;
        return v0;
    }

    protected final String n() {
        String v0 = this.mAdsData == null ? null : this.mAdsData.adLabel;
        return v0;
    }

    protected final int o() {
        return 30;
    }

    protected final void adaptRightImageAdLayoutNight() {
        super.adaptRightImageAdLayoutNight();
        if (this.mRightImageAdImageTagIcon != null) {
            this.mRightImageAdImageTagIcon.setTextColor(ContextCompat.getColor(this.context, com.ss.android.article.browser.R.color.ssxinzi7));
            this.mRightImageAdImageTagIcon.setBackgroundResource(com.ss.android.article.browser.R.drawable.appointment_ad_textpage);
        }
    }
}

